package com.aode.music.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.aode.common.bean.request.LoginData;
import com.aode.common.bean.response.User;
import com.aode.common.bean.web.Result;
import com.aode.music.repository.WebRepository;
import com.aode.utils.sharedhelper.SharedHelper;

public class LoginViewModel extends AndroidViewModel {
    private WebRepository repository;
    private SharedHelper sharedHelper;
    public LoginViewModel(@NonNull Application application) {
        super(application);
        this.repository  = new WebRepository(application);
        sharedHelper = new SharedHelper(application.getApplicationContext());
    }


    public void Login(LoginData loginData){
//        getLogin().observe(getApplication(), userResult -> {
//            if(userResult.getCode().equals("0")){
//                if(userResult.getData()!=null){
//                    User user = userResult.getData();
//                    sharedHelper.save(user.getUserId().toString(),user.getUserName(),user.getUserPassword());
//                }
//            }
//
//        });
         repository.Login(loginData);
    }



    public MutableLiveData<Result<User>> getLogin(){

       return repository.getLoginMutableLiveData();
    }
}
